<template>
	<el-dialog title="编辑工号" visible :show-close="false" class="wrap" size="tiny">
        <i class="el-icon-close close" @click="cancel"></i>
        <el-form label-width="80px" class="form">
            <el-form-item label="工号">
                <el-input v-model="jobNumber"></el-input>
            </el-form-item>
            <el-form-item label="工号密码">
                <el-input v-model="password"></el-input>
            </el-form-item>
            <el-form-item label="选择老师">
                <el-select filterable  v-model="teacher" placeholder="请选择老师" class="select-block">
                    <el-option value="0" label="暂不选择"></el-option>
                    <el-option :label="v.zwm" :value="v.id" v-for="v in teacherList"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <el-button type="info" class="submit" @click="submit">添加</el-button>
    </el-dialog>
</template>

<script type="text/javascript">
	export default {
		data () {
			return {
				jobNumber: '',
				password: '',
				teacher: '',
				teacherList: []
			}
		},
		created () {
			this.getTeacherList();
		},
		methods: {
			submit () {
                this.$store.state.loading = true;
				if (!this.jobNumber) {
					this.$message.warning('请填写工号');
					return;
				}else if(!this.password){
					this.$message.warning('请填写工号密码');
					return;
				}
                this.axios.get( this.$store.state.api + 'ls/add', {
                    params: {
                        gh: this.jobNumber,
                        mm: this.password, 
                        empid: this.teacher
                    }
                }).then( res => {
                    console.log(res)
                    if (res.data.code == 1) {
                    	this.$emit('close',{type:'add',cancel:false});
                        this.$store.state.loading = false;
                    }else{
                    	this.$emit('close',{type:'add',cancel:false});
                    	this.$store.state.loading = false;
                    }
                    
                }).catch( res => {
                    console.log(res)
                	this.$emit('close',{type:'add',cancel:false});
                	this.$store.state.loading = false;
                })
            },
            cancel () {
                this.$emit('close',{type:'add',cancel:true})
            },
            getTeacherList () {
                this.axios.get( this.$store.state.api + 'emp/list')
                .then( res => {
                    console.log(res)
                    this.teacherList = res.data.data.list;
                }).catch( res => {
                    console.log(res)
                })
            }
		}
	}
</script>

<style lang="less" scoped>
    .wrap {
        text-align: center;
    }
    .form {
        // width: 300px;
    }
    .select-block {
        display: block;
    }
    .submit {
        width: 120px;
    }
</style>